import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
} from 'react-native';
import ChooseCity from "./chooseCity";
import MyToolbarSimple from '../../comps/normal/myToolBarSimple'
import ChooseList from "../../comps/list/myChooseProvinceList";
import NetUtil from "../../util/NetWorkUtil";
import UrlUtils from '../../util/UrlCollection'

export default class ChooseProvince extends React.Component {

    constructor() {
        super();
        this.state = {
            loading: 'false',
            firstAll: [],
            data: '',
        }
    }

    /**
     * 在生命周期函数中判断是否进行数据的请求
     */
    componentDidMount() {
        if (this.state.loading == 'false') {
            this.getData()
        } else {

        }
    }

    render() {
        if (this.state.loading === 'false') {
            return (
                <View style={{flex: 1}}>
                    <MyToolbarSimple th={this} title="选择省份"/>
                    <View style={styles.container}>
                        <Text>loading............</Text>
                    </View>
                </View>
            );
        } else {
            //数据展示界面
            return (
                <View style={{flex: 1}}>
                    {/*标题栏*/}
                    <MyToolbarSimple th={this} title="选择省份"/>
                    {/*带侧边导航的城市列表*/}
                    <ChooseList
                        comp={ChooseCity}
                        isSchool={false}
                        data={this.state.data}
                        nav={this.props.navigator}
                        nameId="province"
                    />
                </View>
            );
        }
    }

    /**
     * 请求数据
     */
    getData() {
        NetUtil.get(
            UrlUtils.chooseProvince,
            {'cityId': "1"},
            (data) => {
                this.setState({
                    loading: 'true',
                    data: data
                });
            })
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
    },
});
